from selenium import webdriver
from time import sleep

try:
    driver = webdriver.Chrome()
    driver.get('http://localhost/ranzhi/www/sys/user-login.html')
    driver.maximize_window()
    driver.implicitly_wait(10)

    # 登陆
    driver.find_element_by_id('account').send_keys('admin')
    driver.find_element_by_id('password').send_keys('123456')
    driver.find_element_by_id('submit').click()

    # 获取用户的真名
    realname = driver.find_element_by_xpath('//*[@id="mainNavbar"]/div/ul[1]/li/a').text
    # 判断登陆功能用例是否成功
    if realname == 'admin':
        print('用例运行成功！')
    else:
        print('用例运行失败！')

    # 用页面占用的内容进行断言
    assert realname == 'admin','用例运行失败'

    # 用页面标题进行断言
    assert driver.title == '然之协同','用例运行失败'

    # 用地址栏进行断言
    assert driver.current_url == 'http://localhost/ranzhi/www/sys/index.html','用例运行失败'


finally:
    sleep(2)
    driver.close()